const { app, BrowserWindow ,ipcMain} = require('electron')
const pkg = require('./package.json')
const path = require('path')
const lwin = null
function createWindow () {
  const win = new BrowserWindow({
    width: 1022,
    height: 670,
    webPreferences: {
      nodeIntegration: true
    }
  })
  if (!pkg.production){
    win.webContents.openDevTools()
    win.loadURL('http://localhost:8000/')
  }else{
    win.loadURL('./build/index.html')
  }
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})
app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow()
  }
})
ipcMain.on('openLyricWindow',()=>{
  lwin = new BrowserWindow({
    width: 600,
    height: 200,
  })
  lwin.loadURL(path.join('file:',__dirname,'src/lyricwindow/index.html'))
  lwin.webContents.openDevTools();
  lwin.on('closed',()=>{
        lwin=null;
  })
})
ipcMain.on("closeLyricWindow",()=>{
  lwin = null
})